package io.wdb.wxapp.model;

import java.util.ArrayList;
import java.util.List;

import org.springframework.util.ObjectUtils;

import io.wdb.modules.activity.wxapp.entity.HdUserRankEntity;

public class HdWxGroupReadRecordModel {
	private String user_name;
	private String imgurl;
	private int book_count;
	private String cumulative_time;
	private String rank_percentage;
	private int rank;
	
	public String getUser_name() {
		return user_name;
	}
	public void setUser_name(String user_name) {
		this.user_name = user_name;
	}
	public String getImgurl() {
		return imgurl;
	}
	public void setImgurl(String imgurl) {
		this.imgurl = imgurl;
	}
	public int getBook_count() {
		return book_count;
	}
	public void setBook_count(int book_count) {
		this.book_count = book_count;
	}
	public String getCumulative_time() {
		return cumulative_time;
	}
	public void setCumulative_time(String cumulative_time) {
		this.cumulative_time = cumulative_time;
	}
	public String getRank_percentage() {
		return rank_percentage;
	}
	public void setRank_percentage(String rank_percentage) {
		this.rank_percentage = rank_percentage;
	}
	public int getRank() {
		return rank;
	}
	public void setRank(int rank) {
		this.rank = rank;
	}
	
	public static HdWxGroupReadRecordModel convert(HdUserRankEntity entity){
		if(ObjectUtils.isEmpty(entity)) {
			return null;
		}
		HdWxGroupReadRecordModel model = new HdWxGroupReadRecordModel();
		model.setBook_count(entity.getReadCount());
		if(ObjectUtils.isEmpty(entity.getNickname()) || "null".equals(entity.getNickname()) ) {
			model.setImgurl("https://img.wdb007.com/user_head/default.png");
		}else {
			model.setImgurl(entity.getAvatar());
		}
		if(ObjectUtils.isEmpty(entity.getNickname()) || "null".equals(entity.getNickname()) ) {
			if(ObjectUtils.isEmpty(entity.getMobile())) {
				model.setUser_name("用户"+entity.getRank());
			}else {
				if(entity.getMobile().length() > 7) {
					model.setUser_name(entity.getMobile().substring(0, 3) + "****" + entity.getMobile().substring(7));
				}
			}
		}else {
			model.setUser_name(entity.getNickname());
		}
		
		model.setRank(entity.getRank());
		return model;
	}
	
	public static List<HdWxGroupReadRecordModel> convert(List<HdUserRankEntity> entities){
		List<HdWxGroupReadRecordModel> models = new ArrayList<HdWxGroupReadRecordModel>();
		if(ObjectUtils.isEmpty(entities) || entities.size() == 0) {
			return models;
		}
		for(HdUserRankEntity entity:entities) {
			models.add(convert(entity));
		}
		
		return models;
	}

}
